package com.sunkq.aqs;

public class MutilProducerConsumerByCondition {
    public static void main(String[] args) {
        ResourceByCondition r = new ResourceByCondition();
        MutilProducer pro = new MutilProducer(r);
        MutilConsumer con = new MutilConsumer(r);
        //生产者线程
        Thread t0 = new Thread(pro,"t0");
        Thread t1 = new Thread(pro,"t1");
        //消费者线程
        Thread t2 = new Thread(con,"t2");
        Thread t3 = new Thread(con,"t3");
        //启动线程
        t0.start();
        t1.start();
        t2.start();
        t3.start();
    }
}

/**
 * @decrition 生产者线程
 */
class MutilProducer implements Runnable {
    private ResourceByCondition r;

    MutilProducer(ResourceByCondition r) {
        this.r = r;
    }

    @Override
    public void run() {
//        while (true) {
//            r.product("北京烤鸭");
//        }
//        for (int i = 0; i < 3; i++) {
            r.product("北京烤鸭");
//        }
    }
}

/**
 * @decrition 消费者线程
 */
class MutilConsumer implements Runnable {
    private ResourceByCondition r;

    MutilConsumer(ResourceByCondition r) {
        this.r = r;
    }

    @Override
    public void run() {
//        while (true) {
//            r.consume();
//        }
//        for (int i = 0; i < 3; i++) {
            r.consume();
//        }
    }
}
